/*
 * SyncApplication.java
 *
 * Created on April 12, 2007, 1:34 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.admin;

import org.atomojo.app.App;
import org.atomojo.app.Storage;
import org.atomojo.app.db.DB;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.restlet.routing.Template;

/**
 *
 * @author alex
 */
public class SyncApplication extends Application
{
   
   DB db;
   Storage storage;
   /** Creates a new instance of SyncApplication */
   public SyncApplication(Context context,DB db,Storage storage)
   {
      super(context);
      this.db = db;
      this.storage = storage;
      getTunnelService().setEnabled(false);
   }
   
   @Override
   public Restlet createRoot() {   
      Router router = new Router(getContext()) {
         public void handle(Request request,Response response)
         {
            request.getAttributes().put(App.DB_ATTR,db);
            request.getAttributes().put(App.STORAGE_ATTR,storage);
            super.handle(request,response);
         }
      };
      router.attach("/journal",JournalResource.class);
      router.attach("/local",SyncTargetsResource.class);
      router.attach("/local/{name}",SyncTargetResource.class);
      router.attach("/remote",RemoteAppsResource.class);
      router.attach("/remote/{name}",RemoteAppResource.class);
      router.attach("/process",SyncProcessesResource.class);
      router.attach("/process/{name}",SyncProcessResource.class);
      router.attach("/process/{name}/start",SyncProcessStartResource.class);
      return router;
      
   }
}
